package com.iRomantic.controller.app;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.iRomantic.common.AppJsonResponse;
import com.iRomantic.common.BaseController;
import com.iRomantic.domain.entity.Hotel;
import com.iRomantic.domain.entity.Invitation;
import com.iRomantic.domain.entity.Picture;
import com.iRomantic.domain.entity.Video;
import com.iRomantic.domain.entity.Wedding;

public class WeddingAppController extends BaseController {
	
	/**
	 * 获取婚礼信息
	 */
	//@Before(CacheInterceptor.class)
	//@CacheName("testCache")
	public void getWedding(){
		AppJsonResponse jsonResult = this.createAppJsonResponse();
		try{
			Wedding wedding = this.getModel(Wedding.class);
			Map<String,Object> result = new HashMap<String,Object>();
			wedding = wedding.findByNumber(wedding.getStr("number"));
			
			if(wedding!=null){
				wedding.setOSSPath();
				result.put("wedding", wedding);
				result.put("hotel", wedding.getHotel());
				result.put("enterprise", wedding.getEnterprise());
				result.put("pictures", wedding.getMainPictures());
				result.put("invitation", wedding.getInvitation());
				jsonResult.setResult(result);
			}else{
				jsonResult.failed("婚礼不存在");
			}
		}catch(Exception e){
			e.getStackTrace();
			jsonResult.error(e.getMessage());
		}
		renderJson(jsonResult);
	}
	
	/**
	 * 获取分享图片列表
	 */
	public void getPictureList(){
		AppJsonResponse jsonResult = this.createAppJsonResponse();
		Wedding wedding = this.getModel(Wedding.class);
		List<Picture> pictureList = wedding.getPictures();
		Picture.DAO.setOSSPath(pictureList);
		jsonResult.setResult(pictureList);
		renderJson(jsonResult);
	}
	
	/**
	 * 获取分享视频列表
	 */
	public void getVideoList(){
		AppJsonResponse jsonResult = this.createAppJsonResponse();
		Wedding wedding = this.getModel(Wedding.class);
		List<Video> videoList = wedding.getVideos();
		Video.DAO.setOSSPath(videoList);
		jsonResult.setResult(videoList);
		renderJson(jsonResult);
	}
	
	/**
	 * 获取请帖
	 */
	public void getInvitation(){
		AppJsonResponse jsonResult = this.createAppJsonResponse();
		Wedding wedding = this.getModel(Wedding.class);
		Invitation invitation = wedding.getInvitation();
		jsonResult.setResult(invitation);
		renderJson(jsonResult);
	}

}
